package com.distributeredis.redis_springboot;



import com.distributeredis.redis_springboot.springcache.vo.User;
import org.apache.commons.collections4.ListUtils;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
/*
Apache的ListUtils工具类  交集并集补集差集
 */
public class ListUtilsTest {
    // 交集
    @Test
    public void test1() {
        List<User> users1 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "李四", 14, "打游戏", "洛阳"),
                new User(3, "王五", 15, "旅游", "郑州"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> users2 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "小红", 114, "上天", "广东"),
                new User(3, "小明", 151, "入地", "广西"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> userList = ListUtils.intersection(users1, users2);
        System.out.println(userList);
    }

    // 差集
    @Test
    public void test2() {
        List<User> users1 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "李四", 14, "打游戏", "洛阳"),
                new User(3, "王五", 15, "旅游", "郑州"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> users2 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "小红", 114, "上天", "广东"),
                new User(3, "小明", 151, "入地", "广西"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> userList = ListUtils.subtract(users1, users2);
        System.out.println(userList);
    }

    // 并集不去重
    @Test
    public void test3() {
        List<User> users1 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "李四", 14, "打游戏", "洛阳"),
                new User(3, "王五", 15, "旅游", "郑州"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> users2 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "小红", 114, "上天", "广东"),
                new User(3, "小明", 151, "入地", "广西"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> userList = ListUtils.union(users1, users2);
        System.out.println(userList);
    }

    // 并集并且去重
    @Test
    public void test4() {
        List<User> users1 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "李四", 14, "打游戏", "洛阳"),
                new User(3, "王五", 15, "旅游", "郑州"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> users2 = Arrays.asList(new User(1, "张三", 13, "学习", "河南"),
                new User(2, "小红", 114, "上天", "广东"),
                new User(3, "小明", 151, "入地", "广西"),
                new User(4, "赵六", 16, "游泳", "周口")
        );

        List<User> userList = ListUtils.sum(users1, users2);
        System.out.println(userList);
    }

}
